 <div class="tab-pane fade" id="discount">
	<div class="span12">
		<div class="box gradient">
		<div class="title">
	<h4 class="clearfix">
                
            <span>Discount </span>   <span class="box-form right discount_bar">
               		<button class="btn  btn-mini addDiscount" type="button">Add Discount</button>
               </span>
            </h4>
            </div>
	<div class="content scrollable clearfix">
		<table class="table table-bordered table-vertical-centre discountTable">
			<thead>
				<tr>
					<th><a class="select_all"><span class="icomoon-icon-checkmark-2"></span></a></th>
					<th>Customer Group </th>
					<th>Quantity </th>
					<th>Priority </th>
					<th>Price </th>
					<th>Date Start </th>
					<th>Date End </th>
					<th>Action </th>
				</tr>
			</thead>
 		</table>
 		</div>
 		</div>
	</div>
</div>

<script>
 
 

$(document).ready(function(){
	$("a[href='#discount']").click(function (e) {
		   if (!$(this).hasClass("inited")){
			   $(this).addClass("inited");
			   
			   setTimeout(function(){
				   
					
					var del = {
							id : 'discountDel',
							text  : 'Del',
							domain : "Product Discount",
							operation : "Del",
							url : "${ctx}/admin/product-discount/del/",
							selector : ".discount_bar",
							selects  : $('.discountTable'),
					  
					};
					johnny.tableBtn(del);
					
				 	
					
					$('.addDiscount').click(function(){
					 $("#discountDiv input[name='action']").val("${ctx}/admin/product-discount/create/");
				 	 $("#discountDiv").modal('show');
				  });
					
					  $(document).delegate('.discountTable .icomoon-icon-pencil', 'click', function(event) {
						  
						  	var id = $(this).parent().attr("dataid");
							$.ajax({
								url : "${ctx}/admin/product-discount/"+id+"/edit/",
								type : "GET",
								dataType : "json",
								success : function(data){		
									if(data && data.state && (data.state.indexOf("ERROR") != -1)){
										johnny.error(data.message);
										return;
									}else{
											var entity = data.entity;
				  							$("#discountDiv [name='quantity']").val(entity.quantity);
											$("#discountDiv [name='priority']").val(entity.priority);
											$("#discountDiv [name='price']").val(entity.price);
											$("#discountDiv [name='discountStart']").val(entity.discountStart.substring(0,10));
											$("#discountDiv [name='discountEnd']").val(entity.discountEnd.substring(0,10));
				 							$("#discountDiv input[name='action']").val("${ctx}/admin/product-discount/"+id+"/edit/");
				     	    				$("#discountDiv").modal('show');
				 					}
								}
							});		  
				 
					     
					    });
				var recordColumn = ['','name','quantity','priority','price','discountStart','discountEnd'];
					
					 $('.discountTable').dataTable({
						"bLengthChange" : true,
						"aoColumnDefs" : [ {
							'bSortable' : false,
							'aTargets' : [0,7 ]
						} ],
				 		"sAjaxSource" : '${ctx}/admin/product-discount/${entity.id}/',
						"createQueryData" : function (aoData){
								return	johnny.initQueryData(aoData, recordColumn);
						},
						"createResult" : function (json, echo){
				 			var dataArray = new Array();
							for ( var i = 0; i < json.result.length; i++) {
								var subArray = new Array();
								var value = johnny.getForSelect(json.result[i].id);
								subArray.push(value);
								subArray.push('');
				 				subArray.push(json.result[i].quantity);
								subArray.push(json.result[i].priority);
								subArray.push(json.result[i].price);
								subArray.push(json.result[i].discountStart);
								subArray.push(json.result[i].discountEnd);
				  				var conf = [{
									link : 'javascript:void(1)',
									dataId : json.result[i].id,
									text : 'edit',
									css  : 'icomoon-icon-pencil'
								} 
								
								];
								subArray.push(johnny.getGridLink(conf)); 
				  				dataArray.push(subArray);
							}
							return {
								sEcho : echo,
								iTotalRecords : json.totalCount,
								iTotalDisplayRecords : json.totalCount,
								aaData : dataArray
							};
						}		
					});
				   
				   
			   },400);

		   }

	});
	 
	
	
	
	
});


</script>